<script>
import Common from "@/mixins/order/commonbg.js";
import OrderService from "@/api/order/OrderService.js";
import PPMForm from "@/crm3.0part7-ppm/core/ppmForm.vue";
export default {
  name: "mstp10461010",
  mixins: [PPMForm, Common],
  data() {
    return {
      //MSTP	拆机	拆机
      // proName: 'MSTP'
       endDay: '',
       money: 0,
       startDate:{
        disabledDate(time) {
          return time.getTime() < Date.now() - 3600 * 1000 * 24 * 1;//限制初始日期
        }
       }
    };
  },
 async mounted() {

    let OldOrderInfo = await this.initCommon();
    let ordProdInstsAttrs = OldOrderInfo.ordProdInstsAttrs;
    let ordProdInsts = OldOrderInfo.ordProdInsts;
    let ordOfferInstFeeInfos = OldOrderInfo.ordOfferInstFeeInfos;
    //是否上传附件，默认否
    this.formData["10461064-141000248"].value="2";
    
    
    if (ordProdInsts&&ordProdInsts.length>0&&ordProdInsts[0].orderSourceId != 10000 && ordProdInsts[0].orderSourceId != 10010) {
         this.formData["10461064-142000774"].isshow = true; //罚金 显示
           ordProdInstsAttrs.forEach((item) => {
              if (item.attrId == "142002037") {
                if(item.attrValue){
                   //合同终止日期
                   this.endDay=item.attrValue
                }
              }
           });
            ordOfferInstFeeInfos.forEach((item) => {
              if (item.amount) {
                  this.money=this.money+ parseInt(item.amount);
              }
           });
            
    }else{
       this.formData["10461064-142000774"].isshow = false; //罚金 隐藏
       this.formData["10461064-100012819"].isshow = false; //罚金收款单位 隐藏
       this.formData["10461064-100013081"].isshow = false; //罚金委托收款单位 隐藏

    }
    //this.endDay=new Date();
  },

  computed: {},
  methods: {

     getEndDate() {
            //退租日期
            let leaseDate= this.formData["10461064-100010021"].value;
            if(this.endDay!=""){
                let breakDay=this.GetNumberOfDays(leaseDate,this.endDay);
                if(breakDay>0){
                    //违约天数
                    this.formData["10461064-142000774"].value=(((breakDay*this.money)/30)*0.3).toFixed(2);
                }else{
                    this.formData["10461064-142000774"].value=0;
                }
                //超过3个月
                if(breakDay>90){
                    //是否上传附件，默认是
                    this.formData["10461064-141000248"].value="1"
                }
            }else{
                this.formData["10461064-142000774"].value=0;
            }

    },

    GetNumberOfDays(date1,date2){//获得天数
        //date1：开始日期，date2结束日期
        var a1 = Date.parse(new Date(date1));
        var a2 = Date.parse(new Date(date2));
        var day = parseInt((a2-a1)/ (1000 * 60 * 60 * 24));//核心：时间戳相减，然后除以天数
        return day
    },
    StartDate(key) {
      if(key == '10461064-100010082'){
        return this.startDate;
      }
    },
  },
};
</script>